package com.shopping.utill;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtill {
	                 private static SessionFactory sf;
			public static Session getSession(){
				Session session=null;
				Configuration cfr=new Configuration();
				ServiceRegistry sr=new StandardServiceRegistryBuilder().configure().build();
				//链接池。
				 sf=cfr.buildSessionFactory(sr);
				//链接。
				session=sf.openSession();
				return session;
			}
			public static void main(String[] args){
							
			}
			public static void closeSession(Session session){
				if(session!=null){
					session.close();
				}
				if(sf!=null){
					sf.close();
					
				}
			}
}
